<template>
  <div class="app-container">
    <!--日志操作-->
    <el-form ref="ruleForm" :inline="true"  :model="TbLogVO" class="demo-form-inline">

      <el-form-item label="操作人" prop="username">
        <el-input style="width: 200px" v-model="TbLogVO.username" placeholder="操作人"></el-input>
      </el-form-item>

      <el-form-item label="IP地址" prop="ip">
        <el-input style="width: 200px" v-model="TbLogVO.ip" placeholder="IP地址"></el-input>
      </el-form-item>

      <el-form-item label="操作位置" prop="location">
        <el-input style="width: 200px" v-model="TbLogVO.location" placeholder="操作位置"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="logLists">查询</el-button>
        <el-button plain icon="el-icon-delete" @click="onDel">批量</el-button>
      </el-form-item>
    </el-form>

    <el-table
      ref="multipleTable"
      :data="LoginLog"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>

      <el-table-column
        prop="operation"
        label="操作"
        width="180">
      </el-table-column>

      <el-table-column
        prop="method"
        label="方法"
        width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>{{ scope.row.method }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.method }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column
        prop="params"
        label="参数"
        width="120">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>{{ scope.row.params }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.params }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column
        prop="time"
        label="耗时"
        width="120"
        sortable
     >
        <template slot-scope="scope">
          <el-tag type="success">{{scope.row.time}}ms</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        prop="location"
        label="操作地点"
        width="200">
      </el-table-column>

      <el-table-column
        prop="ip"
        label="IP地址"
        width="120">
      </el-table-column>

      <el-table-column
        prop="username"
        label="操作人"
        width="120">
      </el-table-column>

      <el-table-column
        label="操作"
        width="120">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.id)"></el-button>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[7, 10, 15, 20]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
  import {getloginList,delloginList,deleteloginplus} from '@/api/login'
  export default {
    name: "LoginLog",
    data(){
      return{
        multipleSelection: [],
        current: 1,
        size: 7,
        TbLogVO: {
          username: '',
          ip: '',
          location: ''
        },
        total: 100,
        LoginLog: []
      }

    },
    created() {
      this.logLists();
    },
    methods: {
      //分页查询
      logLists() {
        getloginList(this.current, this.size, this.TbLogVO).then(res => {
          this.LoginLog = res.data.records.records
          this.total = res.data.total
        })
          .catch(err => {
          })
      },
      //删除操作
      del(id) {
        delloginList(id).then(res => {
          this.logLists();
        })
          .catch(err => {
          })
      },
      handleSizeChange(val) {
        this.size = val;
        this.logLists();
      },
      handleCurrentChange(val) {
        this.current = val;
        this.logLists();

      },
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      onDel(){
        var ids=[];
        for (let i = 0; i <this.multipleSelection.length ; i++) {
          ids[i]=this.multipleSelection[i].id
        }
        deleteloginplus(ids).then(res=>{
          console.log("ok")
          this.logLists();
        })
      }
    }
  }
</script>

<style scoped>

</style>
